package git.soulbgm.task;

import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 测试任务
 *
 * @author SoulBGM
 * @date 2023-02-14
 */
@Component
public class TestTask {

    private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");

    @Scheduled(cron = "0/2 * * * * ?")
    @SchedulerLock(name = "outputNowDate", lockAtMostFor = "1900", lockAtLeastFor = "1s")
    public void outputNowDate() {
        String nowDate = LocalDateTime.now().format(formatter);
        System.out.println("北京时间：" + nowDate);
    }

}
